
# import os,sys
# atm_dir = os.path.normpath(os.path.join(os.path.abspath(__file__),os.pardir,os.pardir))
# sys.path.insert(0,atm_dir)
# from atm.bin import *


def shopping(Bank_card):
    # Bank_card = int(input("银行卡额度："))
    shopping_list = [
        ["笔记本电脑",13888],
        ["钢笔",20],
        ["手机",5800],
        ["书包",99],
        ["自行车",400],
        ["电视",3500]
    ]
    shopping_crt = []
    while True:
        print("欢迎光临".center(20,"-"))
        for i,v in enumerate(shopping_list):
            print("%s,%s\t%s"%(i,v[0],v[1]))
        user_choose = input("请选择要购买的商品编号,exit退出:")
        if user_choose.isdigit():
            user_choose = int(user_choose)
            if user_choose >= 0 and user_choose < len(shopping_list):
                goods = shopping_list[user_choose]
                if goods[1] <= Bank_card:
                    Bank_card -= goods[1]
                    shopping_crt.append(goods)
                    print("%s 已加入购物车，您的余额为%s"%(goods[0],Bank_card))
                else:
                    print("您的余额还剩%s，不能购买%s，请选择其他商品："%(Bank_card,goods[0]))
            else:
                print("没有此商品,请重新选择")
        elif user_choose == "exit":
            total = 0
            print("购物清单".center(20,"-"))
            for i in shopping_crt:
                print(i)
                total += i[1]
            print("消费金额总计：",total)
            print("您的余额：",Bank_card)
            break


